<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">操作时间：</label>
            <div class="layui-input-inline seller-inline-4">
                <input type="text" name="date" id="date" placeholder="开始时间 到 结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="export-operation_log"><i class="iconfont icon-msnui-cloud-download" style="font-size: 20px !important;"></i>导出</button>
                <!-- <button class="layui-btn layui-btn-sm"  lay-submit lay-filter="delete-operation_log">删除</button> -->
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="operationTable" lay-filter="operation"></table>
</div>
<div id="exportOperationLog" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先选中或筛选要导出的数据
                </blockquote>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<script>
    var pid = 1;
    layui.use(['form', 'layedit', 'laydate', 'table'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate;
        //时间插件
        laydate.render({
            elem: '#date',
            range: '到',
            format: 'yyyy-MM-dd',
            trigger: 'click' //自动弹出控件的事件，采用click弹出
        });
        var operationTables = layui.table.render({
            elem: '#operationTable',
            height: 'full-99',
            cellMinWidth: '80',
            page: true,
            limit: '20',
            url: "{:url('OperationLog/index')}?_ajax=1",
            id: 'operationTable',
            cols: [
                [{
                    type: 'checkbox'
                }, {
                    field: 'id',
                    width: 90,
                    title: 'ID',
                    align: 'center'
                }, {
                    field: 'username',
                    title: '操作员',
                    width: 130,
                    align: 'center'
                }, {
                    field: 'ctime',
                    title: '操作时间',
                    width: 170,
                    align: 'center'
                }, {
                    field: 'desc',
                    title: '操作描述',
                    align: 'center'
                }, {
                    field: 'content',
                    title: '操作内容',
                    align: 'center'
                }, {
                    field: 'ip',
                    title: '操作IP',
                    width: 150,
                    align: 'center'
                }]
            ]
        });

        //筛选条件
        form.on('submit(*)', function(data) {
            operationTables.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //操作日志导出
        layui.form.on('submit(export-operation_log)', function(data) {

            layer.open({
                type: 1,
                title: '操作日志导出',
                area: setpage(400, 290), //宽高
                btn: ['确定', '取消'],
                content: $("#exportOperationLog").html(),
                yes: function() {
                    //判断是否有选中
                    var checkStatus = layui.table.checkStatus('operationTable');
                    var checkData = checkStatus.data;
                    var length = checkStatus.data.length;
                    var ids = [];
                    if (length) {
                        $.each(checkData, function(i, obj) {
                            ids.push(obj.id);
                        });
                    }

                    //判断是否有选中
                    var filter = $(".seller-form").serialize();
                    filter += '&ids=' + ids;
                    $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                    var data = $(".export-form:last").serializeArray();

                    data.push({
                        'name': 'model',
                        'value': 'OperationLog'
                    });

                    JsPost("{:url('Ietask/export')}", data, function(res) {
                        layer.msg(res.msg, {
                            time: 1500
                        }, function() {
                            if (res.status) {
                                operationTables.reload({
                                    where: data.field,
                                    page: {
                                        curr: 1
                                    }
                                });
                                layer.closeAll();
                            }
                        });
                    });
                },
                btn2: function() {
                    layer.closeAll();
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //删除用户
        layui.form.on('submit(delete-operation_log)', function(data) {
            var checkStatus = layui.table.checkStatus('operationTable');
            var checkData = checkStatus.data;
            var operate = data.value;
            var length = checkStatus.data.length;
            if (length <= 0) {
                layer.msg("请先选要操作的数据");
                return false;
            }
            var ids = [];
            $.each(checkData, function(i, obj) {
                ids.push(obj.id);
            });
            layer.confirm('确认删除选中日志吗？', {
                title: '提示',
                btn: ['确认', '取消'] //按钮
            }, function() {
                JsPost("{:url('OperationLog/delLog')}", {
                    'ids': ids
                }, function(res) {
                    if (res.status) {
                        layer.msg(res.msg);
                        layui.table.reload('operationTable');
                    } else {
                        layer.msg(res.msg);
                    }

                });
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>